home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBTerminalInput.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  1.9 KB  |  85 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBTerminalInput string -- Feed the string to the terminal emulator, independent of any other input.
  3.  
  4.     To compile and link this file using Macintosh Programmer's Workshop,
  5.  
  6.         pascal -w CTBTerminalInput.p
  7.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=2764 -sn Main=CTBTerminalInput ∂
  8.             CTBTerminalInput.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  9.  
  10.     © Copyright 1990 by Apple Computer, Inc.
  11.  
  12.     Initial coding 2/90 by Harry R. Chesley.
  13. *)
  14.  
  15. {$R-}
  16.  
  17. {$S CTBTerminalInput }     { Segment name must be the same as the command name. }
  18.  
  19. unit DummyUnit;
  20.  
  21. interface
  22.  
  23. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  24.  
  25. procedure EntryPoint(paramPtr: XCmdPtr);
  26.     
  27. implementation
  28.  
  29. procedure CTBTerminalInput(paramPtr: XCmdPtr); forward;
  30.  
  31. procedure EntryPoint(paramPtr: XCmdPtr);
  32.  
  33.     begin
  34.         CTBTerminalInput(paramPtr);
  35.     end;
  36.  
  37. procedure CTBTerminalInput(paramPtr: XCmdPtr);
  38.  
  39.     {$I CTBUtil.inc}
  40.  
  41.     var p: Ptr;
  42.         l, l2: longInt;
  43.         h: Handle;
  44.  
  45.     procedure Fail(errMsg: Str255); { set theResult and quit }
  46.         begin
  47.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  48.             exit(CTBTerminalInput);
  49.         end;
  50.  
  51.     begin
  52.         { Check the parameter count. }
  53.         if paramPtr^.paramCount <> 1 then Fail('Invalid parameter count');
  54.  
  55.         { Check for an empty string being sent. }
  56.         if not ParmPresent(1) then exit(CTBTerminalInput);
  57.         h := paramPtr^.params[1];
  58.  
  59.         { Make sure we've got the Comm Toolbox around. }
  60.         CTBReady;
  61.         { And that there's a terminal tool. }
  62.         EnsurePresent(terminalTool);
  63.  
  64.         { Get the size of the input. }
  65.         HLock(h);
  66.         p := h^;
  67.         l := 0;
  68.         while p^ <> 0 do
  69.             begin
  70.                 p := Ptr(ord4(p)+1);
  71.                 l := l+1;
  72.             end;
  73.         p := h^;
  74.         { Feed it to the terminal tool (even it is won't take in one gulp). }
  75.         while l > 0 do
  76.             begin
  77.                 l2 := TMStream(Globals^^.termHand,p,l,0);
  78.                 p := Ptr(ord4(p)+l2);
  79.                 l := l - l2;
  80.             end;
  81.         HUnlock(h);
  82.     end;
  83.  
  84. end.
  85.